package com.qudian.pay.notify.dingtalk.utils;

import com.qudian.pay.notify.dingtalk.DingtalkChatbotClient;
import com.qudian.pay.notify.dingtalk.SendResult;
import com.qudian.pay.notify.dingtalk.demo.WebhookConfig;
import com.qudian.pay.notify.dingtalk.message.ActionCardAction;
import com.qudian.pay.notify.dingtalk.message.ActionCardMessage;

public class DingAlertUtils {
	
	private static DingtalkChatbotClient client = new DingtalkChatbotClient();
	
	public static SendResult sendMsg(String title,String content) {
		return sendMsg(title,content,WebhookConfig.financeWebhook);
	}
	
	public static SendResult sendMsgWithLink(String title,String content,String link,String webhook) {
		ActionCardMessage message = new ActionCardMessage();
		message.setBriefTitle(title);
		message.setBriefText(content);
		ActionCardAction action = new ActionCardAction("查看详情", link);
		message.addAction(action);
		return client.send(webhook, message);
	}
	
	public static SendResult sendMsg(String title,String content,String webhook) {
		ActionCardMessage message = new ActionCardMessage();
		message.setBriefTitle(title);
		message.setBriefText(content);
		ActionCardAction action = new ActionCardAction("查看详情", "#");
		message.addAction(action);
		return client.send(webhook, message);
	}
	
	public static void main(String[] args) {
		String title = "Talos系统异常";
		String content = "【2017-06-07】日的厦门信托3期报表推送任务 推送时发生异常\r\n java.lang.NullPointerException: null";
		SendResult sendMsg = DingAlertUtils.sendMsg(title,content,WebhookConfig.testWebhook);
		System.out.println(sendMsg);
	}
}
